import java.io.Serializable;
import java.util.Date;
import java.util.Scanner;

enum UserType {
    ADMIN, MANAGER, FRONT_DESK
}

abstract class User implements Serializable{
    protected String password;
    protected String userId;
    final String username;
    final Date registerTime;
    final UserType userType;
    protected String phone;
    Scanner scanner=new Scanner(System.in);

    //初始化员工属性的入口
    public User(String userId, String username, String password, UserType userType, String phone){
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.registerTime = new Date();
        this.userType = userType;
        this.phone = phone;
    }

    //验证是否为当事人
    public boolean checkPassword(String password){
        return this.password.equals(password);
    }

    //修改自身密码的入口，必须先验证身份
    public boolean changeOwnPassword(){
        System.out.print("请输入当前密码: ");
        String oldPassword = scanner.nextLine();
        System.out.print("请输入新密码: ");
        String newPassword = scanner.nextLine();

        if (checkPassword(oldPassword)) {
            this.password = newPassword;
            System.out.println("密码修改成功");
            return true;
        }
         else {
            System.out.println("密码修改失败: 当前密码不正确");
            return false;
        }
    }

    //修改自身手机号的入口
    public boolean changeOwnPhone(){
        System.out.print("请输入当前密码: ");
        String oldPassword = scanner.nextLine();
        System.out.print("请输入新密码: ");
        String newPassword = scanner.nextLine();

        if (checkPassword(oldPassword)) {
            System.out.println("请输入修改后的手机号");
            this.phone=scanner.nextLine();
            System.out.println("手机号修改成功");
            return true;
        }
        else {
            System.out.println("密码修改失败: 当前密码不正确");
            return false;
        }
    }

    //员工可随意查看自身属性
    public String getUserId(){
        return userId;
    }
    public String getUsername(){
        return username;
    }
    public Date getRegisterTime(){
        return registerTime;
    }
    public UserType getUserType(){
        return userType;
    }
    public String getPhone(){
        return phone;
    }

    //员工各自的工作菜单
    public abstract void menu();

}

